package startupweekend201311.recipe4u.fragment;

import java.util.ArrayList;

import startupweekend201311.recipe4u.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;

public class SearchRecipeFragment extends Fragment {
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.flagment_searchrecipe, container, false);
	}
	
	@Override
	public void onResume() {
		super.onResume();

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // アイテムを追加
        adapter.addAll(new String[]{"お肉のおかず","魚介のおかず","たまご・大豆加工品"});
        Spinner spinner = (Spinner) getActivity().findViewById(R.id.spin_category);
        // アダプターを設定
        spinner.setAdapter(adapter);
        // スピナーのアイテムが選択された時に呼び出されるコールバックリスナーを登録
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {

                ArrayList<ItemBindData> dataObj = new ArrayList<ItemBindData>();
                switch(position){
                case 0:
                	dataObj.add(new ItemBindData("ステーキ", R.drawable.sy_009));
	                dataObj.add(new ItemBindData("焼肉盛り合わせ", R.drawable.sy_199));
                	break;
                case 1:
	                dataObj.add(new ItemBindData("御造り", R.drawable.sy_020));
	                break;
                case 2:
	                dataObj.add(new ItemBindData("大豆と鶏肉のサンドイッチ", R.drawable.sy_246));
	                dataObj.add(new ItemBindData("きのことホワイトソースのパスタ", R.drawable.sy_036));
	                break;
                }
                
                ListView listView = (ListView) getActivity().findViewById(R.id.listView);
                listView.setAdapter(
        				new CustomListAdapter(getActivity().getApplicationContext(), dataObj));
            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });
	}
}
